package se.wangs.prototype;

/**
 * -- coding: UTF-8 -- *
 *
 * @author wangs
 * @date 2023/12/6 9:08
 * @description 具体原型类
 */
public class Student implements Cloneable{
    private String idNo;
    private String name;
    private Teacher teacher;

    public String getIdNo() {
        return idNo;
    }

    public void setIdNo(String idNo) {
        this.idNo = idNo;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Teacher getTeacher() {
        return teacher;
    }

    public void setTeacher(Teacher teacher) {
        this.teacher = teacher;
    }

    @Override
    public Student clone() {
        try {
            Student clone = (Student) super.clone();
            // 获得原来的 teacher 对象，并clone出一个新的teacher对象
            Teacher newTeacher = clone.getTeacher().clone();
            // 重新设置teacher
            clone.setTeacher(newTeacher);
            return clone;
        } catch (CloneNotSupportedException e) {
            throw new AssertionError();
        }
    }
}
